<template>
  <div id="Barnd" ref="BrandList" v-show="this.brandShow">
    <header id="header3">
      <router-link to slot="left" class="back">
        <img src="../../../static/m_img/back.png" alt class @click="handleBack()">
      </router-link>
      <p class="ellipsis-1">选择车辆品牌</p>
    </header>
    <!-- 车牌 -->
    <mt-index-list>
      <div class="hotBrand">
        <p>热门品牌</p>
        <ul class="clearfix">
          <li v-for="(item,index) in hotBrands" :key="index" @click="seriesPoup(item.brandId,item.brandName)">
            <img :src="item.logoUrl" alt>
            <span>{{item.brandName}}</span>
          </li>
        </ul>
      </div>
      <mt-index-section :index="item.title" v-for="(item,index) in brands" :key="index">
        <div
          class="brandBox"
          v-for="(brand,index) in item.carBrands"
          :key="index"
          @click="seriesPoup(brand.brandId,brand.brandName)"
        >
          <img :src="brand.logoUrl" alt>
          <p>{{brand.brandName}}</p>
        </div>
      </mt-index-section>
    </mt-index-list>
    <!-- 车系 -->
    <mu-drawer :open.sync="open" :docked="docked" :right="position === 'right'">
      <mu-list>
        <mu-list-item button @click="handleBackSeries">
          <mu-list-item-title><上一级</mu-list-item-title>
        </mu-list-item>
        <!-- @click="handleSeries(city.cityName)" -->
        <div button v-for="(series,index) in seriesList" :key="index">
          <p class="seriesType">{{series.title}}</p>
          <mu-list-item
            v-for="(item,index) in series.carSeries"
            :key="index"
            @click.native="modelPoup(item.seriesId,item.brandId,item.seriesName)"
          >
            <mu-list-item-title>{{item.seriesName}}</mu-list-item-title>
          </mu-list-item>
        </div>
      </mu-list>
    </mu-drawer>
    <!-- 车型 -->
    <mu-drawer :open.sync="openModel" :docked="docked" :right="position === 'right'">
      <mu-list>
        <mu-list-item button @click="handleBackModel">
          <mu-list-item-title><上一级</mu-list-item-title>
        </mu-list-item>
        <div button v-for="(model,index) in modelList" :key="index">
          <p class="seriesType">{{model.title}}款</p>
          <mu-list-item
            v-for="(item,index) in model.carModels"
            :key="index"
            @click.native="handleModel(item.brandId,item.modelId,item.modelName,item.seriesId)"
          >
            <mu-list-item-title>{{item.modelName}}</mu-list-item-title>
          </mu-list-item>
        </div>
      </mu-list>
    </mu-drawer>
  </div>
</template>
<script>
import vHeader3 from "./Header3";
import { getReq } from "../../assets/js/api.js";
export default {
  data() {
    return {
      ListHeight: "",
      // 车牌列表
      brands: [],
      hotBrands:[],
      //   当前车牌
      curBrandName: "",
      curBrandId: "",
      //   车系列表
      seriesList: [],
      //   当前车系
      curSriesdName: "",
      curSriesdId: "",
      curBrandId: "",
      // 车型列表
      modelList: [],
      //   当前车型
      curModeldId: "",
      curModeldName: "",
      //打开车系
      open: false,
      //打开车型
      openModel: false,
      position: "right",
      docked: true
    };
  },
  props: {
    brandShow: Boolean
  },
  components: { vHeader3 },
  methods: {
    //   indexList高度
    indexListHeight() {
      let winHeight =
        window.innerHeight ||
        document.documentElement.clientHeight ||
        document.body.clientHeight;
      this.ListHeight = winHeight + 44;
    },
    // 获取品牌名称
    getBrands() {
      getReq("/app/config/getAllCarBrands").then(res => {
        let { errcode, message, content } = res;
        if (errcode == 0) {
          this.brands = content.carBrands;
          this.hotBrands=content.hotCarBrands
        }
      });
    },
    // 打开车系列表
    seriesPoup(brandId, brandName) {
      this.curBrandName = brandName;
      var params = {
        brandId: brandId
      };
      getReq("/app/config/getCarSeriesByBrandId", params).then(res => {
        let { content, errcode, message } = res;
        if (errcode == 0) {
          this.open = true;
          this.seriesList = content;
        }
      });
    },
    //打开车型列表
    modelPoup(seriesId, brandId, seriesName) {
      this.curSriesdName = seriesName;
      this.openModel = true;
      let params = {
        brandId: brandId,
        seriesId: seriesId
      };
      getReq("/app/config/getCarModelsByBidAndSerId", params).then(res => {
        let { errcode, message, content } = res;
        if (errcode == 0) {
          this.modelList = content;
          // console.log(this.modelList);
        } else {
          errorRes(errcode, message);
        }
      });
    },
    // 点击车型
    handleModel(brandId, modelId, modelName, seriesId) {
      this.openModel = false;
      this.curSriesdId = seriesId;
      this.curBrandId = brandId;
      this.curModeldId = modelId;
      this.curModeldName = modelName;
      this.$emit("listenToBrand", false);
    },
    // back
    handleBack() {
      this.$emit("listenToBrand", false);
    },
    // 回到上一级
    handleBackSeries() {
      this.open = false;
    },
    handleBackModel() {
      this.openModel = false;
    }
  },
  mounted() {
    this.indexListHeight();
    this.getBrands();
  }
};
</script>
<style lang="scss">
#Barnd {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #fff;
  z-index: 10000;
  .mint-cell-text {
    color: #323232;
    font-size: 1.25rem;
  }
  .mint-indexsection-index {
    color: #666;
  }
  .mint-indexlist-navitem {
    color: #007aff;
  }
  .mint-cell-wrapper {
    border-bottom: 1px solid rgba(229, 229, 229, 1);
    padding: 0;
    margin: 0 10px;
    width: auto;
  }
  .mint-indexlist-nav {
    background: transparent;
    border-left: 0px;
  }
  .mint-indexsection-index {
    height: 30px;
    padding: 0 10px;
    line-height: 30px;
    background: #f4f6f8;
  }
  .mint-popup {
    width: 50%;
    height: 100%;
  }
  .mu-list li {
    border-bottom: 1px solid rgba(229, 229, 229, 1);
  }
  .mu-item-sub-title,
  .mu-item-title {
    color: #323232;
    font-size: 1.25rem;
  }
  .seriesType {
    height: 30px;
    background: #f4f6f8;
    padding: 0 10px;
    color: #666;
    line-height: 30px;
  }
  .mu-drawer {
    width: 100%;
  }
  #header3 {
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 44px;
    padding: 0 2%;
    .back img,
    .back {
      width: 9px;
      height: 17.5px;
    }
    p {
      width: 90%;
      text-align: center;
      color: #323232;
      font-size: 1.5rem;
    }
  }

  .brandBox {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #f8f8f8;
    img {
      margin-right: 5%;
      width: 6%;
    }
  }

  .hotBrand {
    ul {
      padding:10px 0;
      li {
        float: left;
        width: 20%;
        text-align: center;
        margin-bottom: 7.5px;
        span {
          display: block;
        }
        img {
          width: 27px;
          height: 27px;
        }
      }
    }
    p {
      height: 30px;
      background: #f4f6f8;
      line-height: 30px;
      color: #666;
      padding: 0 10px;
    }
  }
}
</style>
